package leetcom.Lccup21;

import java.util.Arrays;

public class EX1 {
    public int purchasePlans(int[] nums, int target) {
        Arrays.sort(nums);
        int mod = (int) (1e9+7);

        long res = 0;
        int left = 0;
        int right = nums.length-1;

        while(left<right){

            if(nums[left]+nums[right]>target){
                right--;
            }else {
                res+=(right-left)%mod;
                left++;
            }
        }
        return (int)res%mod;
    }
}
